import React from 'react';
import {
  View,
} from 'react-native';

import IMOne2OnePage from '../im/IMOne2OnePage';
import QZ_ChatItemView from './QZ_ChatItemView';
import DataManager from '../../datas/DataManager';
import IMConstants from '../im/IMConstants';
import Constants from '../../common/Constants';
import ToastUtils from '../../common/ToastUtils';
import SizeUtils from '../../common/SizeUtils';
import QZ_QunliaoChatLinker from '../../datas/im/QZ_QunliaoChatLinker';
import TImage from '../../components/TImage';
import Config from '../../config';
export default class QZ_QunliaoChatPage extends IMOne2OnePage {
  constructor(props) {
    super(props);
     this.group = this.props.pageData.routeData;
  }

  _initLinker() {
    // ToastUtils.show("this.props.pageData.routeData.im_group_id:" + this.props.pageData.routeData.im_group_id);
    this._linker = DataManager.callMethod(Constants.MODULE_TYPE.IM, "getLinker",
      [IMConstants.linkerType.one2one, this.props.pageData.routeData.im_group_id,
        QZ_QunliaoChatLinker, {linkerType:IMConstants.linkerType.one2one,}]);
    this._linker.init({sendMessageCall:this._sendMessageCall.bind(this),
      groupData:this.props.pageData.routeData,
      updateCall:this._onLinkerUpdateCall.bind(this)});
  }

  componentWillUpdate(nextProps, nextState) {
    super.componentWillUpdate(nextProps, nextState);

    if(this.group.routeData != nextProps.pageData.routeData){
      this.group = nextProps.pageData.routeData;
    }
  }

  _dealRenderItem(data, index) {
    data.readed = true;
    return <QZ_ChatItemView data={data} selfData={this._getUserData().userData}
      qunData={this._getUserData()} userData={{}} index={index}
      ref={(ref) => this._itemViewRefs[index] = ref}/>
  }

   _renderNavigationBarRightButtonContent() {
    return (
      <View style={{height:SizeUtils.translateDesignHeightToCode(51), flexDirection:"row",
          alignItems:"center"}}>
        <TImage source={require("../../../resource/images/quanzi/chatroom_btn_Setup.png")}
          style={{width:38, height:36}}/>
      </View>
    )
  }
  
 _onPressNavigationBarRightBtn() {
    this.gotoPage(Config.pages.quanzi_qun_data,this.group);
  }
}
